package org.sundatagroup.aurora.core.entity.model;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.sundatagroup.aurora.core.entity.pojo.Module;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.io.Serializable;

/**
 * <p>模块 {@link Module} 在数据库的数据结构
 * </p>
 * 
 * @author Zdream
 * @date 2018-04-02
 * @since 0.1
 */
@Document(collection = "module")
public class ModuleModel implements Serializable {
	
	private static final long serialVersionUID = 2735958443217160378L;
	
	@Id
    int mid;
    String name;
    String option;
    String path;
    String desc;

    public int getMid() {
        return mid;
    }

    public void setMid(int mid) {
        this.mid = mid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getOption() {
        return option;
    }
    
    public JsonObject getOptionToJson() {
    	if (option == null) {
    		return null;
    	}
    	JsonParser parser = new JsonParser();
    	return parser.parse(option).getAsJsonObject();
    }

    public void setOption(String option) {
        this.option = option;
    }

    public void setOption(JsonObject option) {
        this.option = option.toString();
    }

    public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	@Override
	public String toString() {
		return "ModuleModel [mid=" + mid + ", name=" + name + ", option=" + option + ", path=" + path + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + mid;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ModuleModel other = (ModuleModel) obj;
		if (mid != other.mid)
			return false;
		return true;
	}

}
